package com.yc.hotel.feign.controller;

import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yc.hotel.dto.UserItemDTO;
import com.yc.hotel.service.IUserItemService;

@RestController
@RequestMapping("/userItems")
public class UserItemFeignController {

	@Autowired 
	private IUserItemService userItemService;

	@GetMapping("/findByUno")
	List<UserItemDTO> findByUno(@RequestParam int uno) {
		
		List<UserItemDTO> userItems = userItemService.findByUnoF(uno);
		for(UserItemDTO userItem : userItems) {
			String cardid = userItem.getCardid();
			cardid = cardid.substring(0, 6) + "********" + cardid.substring(14,18);
			userItem.setCardid(cardid);
		}
		return userItems;
	}
	
	@PostMapping("/add")
	int add(@RequestParam UserItemDTO userItem, @RequestParam int uno) {
		
		userItem.setUno(uno);
		int result = userItemService.addF(userItem);
		return result;
	}
}
